package com.jstyle.jclifexd.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.github.zagum.expandicon.ExpandIconView;
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarLayout;
import com.haibin.calendarview.CalendarView;
import com.haibin.calendarview.ExerciseRecodeData;
import com.jstyle.blesdk.Util.SingleDealData;
import com.jstyle.blesdk.callback.DataListener;
import com.jstyle.blesdk.cmdenum.SendCmdState;
import com.jstyle.blesdk.constant.DeviceKey;
import com.jstyle.blesdk.model.DeviceBean;
import com.jstyle.blesdk.model.ExerciseMode;
import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.activity.HealthHistoryActivity;
import com.jstyle.jclifexd.activity.HeartHistoryActivity;
import com.jstyle.jclifexd.activity.HeartTipsActivity;
import com.jstyle.jclifexd.activity.HistoryActivity;
import com.jstyle.jclifexd.activity.TempHistoryActivity;
import com.jstyle.jclifexd.ble.BleManager;
import com.jstyle.jclifexd.ble.BleService;
import com.jstyle.jclifexd.daoManager.HealthDataDaoManager;
import com.jstyle.jclifexd.daoManager.HeartDataDaoManager;
import com.jstyle.jclifexd.daoManager.TempHistoryDataDaoManager;
import com.jstyle.jclifexd.model.BleData;
import com.jstyle.jclifexd.model.HealthData;
import com.jstyle.jclifexd.model.HeartData;
import com.jstyle.jclifexd.model.TemperatureHistoryData;
import com.jstyle.jclifexd.utils.ChartDataUtil;
import com.jstyle.jclifexd.utils.DateUtil;
import com.jstyle.jclifexd.utils.HealthDataUtils;
import com.jstyle.jclifexd.utils.ResolveData;
import com.jstyle.jclifexd.utils.RxBus;
import com.jstyle.jclifexd.utils.Utils;
import com.jstyle.jclifexd.view.TemperatureView;

import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import lecho.lib.hellocharts.view.LineChartView;

import static com.jstyle.blesdk.cmdenum.SendCmdState.Set_EXERCISE_MODE;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HealthTemperatureFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HealthTemperatureFragment extends BaseFragment implements DataListener {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    Unbinder unbinder;
    @BindView(R.id.bt_health_titleLeft)
    Button btHealthTitleLeft;
    @BindView(R.id.bt_health_title)
    Button btHealthTitle;
    @BindView(R.id.ExpandIconView)
    com.github.zagum.expandicon.ExpandIconView ExpandIconView;
    @BindView(R.id.CalendarView_sleep_Month)
    CalendarView CalendarViewSleepMonth;

//    @BindView(R.id.check_heart_measure)
//    CheckBox checkHeartMeasure;
//    @BindView(R.id.iv_heart_measure)
//    ImageView ivHeartMeasure;
//    @BindView(R.id.tv_bpm)
//    TextView tvBpm;
//    @BindView(R.id.tv_hr1810_value)
//    TextView tvHr1810Value;
//    @BindView(R.id.tv_hr_level)
//    TextView tvHrLevel;

    @BindView(R.id.TemperatureView)
    com.jstyle.jclifexd.view.TemperatureView TemperatureView;
    @BindArray(R.array.stress_advice)
    String[] stressAdvice;
    @BindView(R.id.tv_health_heart)
    TextView tvHealthHeart;
    @BindView(R.id.tv_health_hr)
    TextView tvHealthHr;
    @BindView(R.id.LineChartView_health_heart)
    LineChartView LineChartViewHealthHeart;

    @BindView(R.id.tv_temp_pressure)
    TextView tvTempPressure;
    @BindView(R.id.tv_tempValue)
    TextView tvTempValue;
    @BindView(R.id.tv_last_blood)
    TextView tvLastBlood;
    @BindView(R.id.tv_temp_min)
    TextView tvTempMin;
    @BindView(R.id.tv_blood_max)
    TextView tvBloodMax;
    @BindView(R.id.tv_tempMinValue)
    TextView tvTempMinValue;
    @BindView(R.id.tv_temp_maxValue)
    TextView tvTempMaxValue;
    @BindView(R.id.tv_hrv_value)
    TextView tvHrvValue;
    @BindView(R.id.tv_hrv)
    TextView tvHrv;
    @BindView(R.id.iv_hrv_data)
    ImageView ivHrvData;
    @BindView(R.id.tv_hrv_advice)
    TextView tvHrvAdvice;
    @BindView(R.id.IV_HRV_BG)
    ImageView IVHRVBG;
    @BindView(R.id.LL_score)
    LinearLayout LLScore;
    @BindView(R.id.iv_hrv_level0)
    ImageView ivHrvLevel0;
    @BindView(R.id.iv_hrv_level1)
    ImageView ivHrvLevel1;
    @BindView(R.id.iv_hrv_level2)
    ImageView ivHrvLevel2;
    @BindView(R.id.iv_hrv_level3)
    ImageView ivHrvLevel3;
    @BindView(R.id.LL_LEVEL)
    LinearLayout LLLEVEL;
    @BindView(R.id.ScrollView)
    NestedScrollView ScrollView;
    @BindView(R.id.CalendarLayout)
    com.haibin.calendarview.CalendarLayout CalendarLayout;
    @BindArray(R.array.color_hrv_array)
    int[] hrvColor;
    @BindArray(R.array.hrv_advice)
    String[] hrvAdvice;
    @BindView(R.id.iv_temp_data)
    ImageView ivTempData;
    @BindView(R.id.tv_stress_value)
    TextView tvStressValue;
    @BindView(R.id.iv_stress_data)
    ImageView ivStressData;
    @BindView(R.id.tv_body_pressure)
    TextView tvBodyPressure;
    @BindView(R.id.RadioButton_stress1)
    RadioButton RadioButtonStress1;
    @BindView(R.id.RadioButton_stress2)
    RadioButton RadioButtonStress2;
    @BindView(R.id.RadioButton_stress3)
    RadioButton RadioButtonStress3;
    @BindView(R.id.RadioButton_stress4)
    RadioButton RadioButtonStress4;
    @BindView(R.id.RadioGroup_stress)
    RadioGroup RadioGroupStress;
    @BindView(R.id.tv_stress_advice)
    TextView tvStressAdvice;
    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private AnimationDrawable animationDrawable;
    private AnimationDrawable animationDrawableHeart;
    private Disposable subscription;
    @BindArray(R.array.heartRange_array)
    String[] heartArray;
    @BindArray(R.array.hr_color1810_arrays)
    int[] hrColorArrays;
    private Typeface mFace;
    private String findDate;
    @BindArray(R.array.string_hrv_array)
    String[] hrvContent;
    @BindArray(R.array.string_pressure_array)
    String[] stressContent;
    private List<HealthData> todayHealths;

    public HealthTemperatureFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment HealthTemperatureFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static HealthTemperatureFragment newInstance(String param1, String param2) {
        HealthTemperatureFragment fragment = new HealthTemperatureFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_health_temperature, container, false);
        unbinder = ButterKnife.bind(this, view);
        init();
        return view;
    }

    private void init() {
        startMeasureHeart(true);
        if (!Utils.IsRussian(getActivity())) {
            mFace = Typeface.createFromAsset(getActivity().getAssets(), "Brandon_reg.otf");
        } else {
            mFace = Typeface.createFromAsset(getActivity().getAssets(), "SourceHanSansCN-Regular.ttf");
        }
//        checkHeartMeasure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                startMeasureHeart(isChecked);
//            }
//        });
//        radioGroupTemp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, int checkedId) {
//                TemperatureView.setVisibility(checkedId == R.id.RadioButton_Temp ? View.VISIBLE : View.GONE);
//                rlTempHrv.setVisibility(checkedId == R.id.RadioButton_Temp ? View.GONE : View.VISIBLE);
//            }
//        });
        RxBus.getInstance().toObservable(BleData.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<BleData>() {
            @Override
            public void onSubscribe(Disposable d) {
                subscription = d;
            }

            @Override
            public void onNext(BleData bleData) {

                String action = bleData.getAction();
                if (action.equals(BleService.ACTION_DATA_AVAILABLE)) {
                    byte[] value = bleData.getValue();
                    SingleDealData.receiveUpdateValue(value, HealthTemperatureFragment.this);
                } else if (action.equals(BleService.ACTION_GATT_DISCONNECTED)) {
                    startMeasureHeart(false);
                }
            }


            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
        CalendarViewSleepMonth.setOnDateSelectedListener(new CalendarView.OnDateSelectedListener() {
            @Override
            public void onDateSelected(Calendar calendar, boolean isClick) {
                String date = calendar.getYear() + "." + String.format("%02d", calendar.getMonth()) + "." + String.format("%02d", calendar.getDay());
                btHealthTitle.setText(DateUtil.getShowDay(getContext(), date));
                findData(date.substring(2));
            }
        });

        CalendarViewSleepMonth.setOnViewChangeListener(new CalendarView.OnViewChangeListener() {
            @Override
            public void onViewChange(boolean isMonthView) {
                ExpandIconView.switchState();
            }
        });
    }

    private void findData(String date) {
        findDate = date;
        initHeartView(date);
        initHealthData(date);
    }

    private void initHeartView(String queryDate) {
        List<HeartData> heartDataList = HeartDataDaoManager.queryDayData(queryDate);
        int maxDayHr = 0;
        int minDayHr = 300;
        int totalDayHr = 0;
        int count = 0;

        int offsetCount = 5;
        int firstCount = -1;
        HashMap<Integer, Integer> offsetMap = new HashMap<>();
        for (int i = 0; i < heartDataList.size(); i++) {
            HeartData heartData = heartDataList.get(i);
            String date = heartData.getTime();
            int startCount = DateUtil.getMIndex(date, queryDate.split(" ")[0] + " 00:00:00", 1);
            int heartRate = heartData.getHeart();
            // if (startCount >= 1440) break;
            if (heartRate != 0) {
                if (firstCount != -1) {
                    offsetCount = startCount - firstCount;
                    Integer offset = offsetMap.get(offsetCount);
                    if (offset == null) {
                        offsetMap.put(offsetCount, 1);
                    } else {
                        offset++;
                        offsetMap.put(offsetCount, offset);
                    }
                }
                firstCount = startCount;
                count++;
                totalDayHr += heartRate;
                maxDayHr = Math.max(maxDayHr, heartRate);
                minDayHr = Math.min(minDayHr, heartRate);
            }

        }
        int maxOffset = 0;
        int drawOffset = 5;
        for (Map.Entry<Integer, Integer> entry : offsetMap.entrySet()) {
            if (entry.getValue() > maxOffset) {
                maxOffset = entry.getValue();
                drawOffset = entry.getKey();
            }
        }
//        if (drawOffset < 5) drawOffset = 5;
//        if (drawOffset > 60) drawOffset = 60;
        int[] heartArray = new int[1440];//24*60分钟
        for (int i = 0; i < heartDataList.size(); i++) {
            HeartData heartData = heartDataList.get(i);
            String date = heartData.getTime();
            int startCount = DateUtil.getMIndex(date, queryDate.split(" ")[0] + " 00:00:00", 1);
            int heartRate = heartData.getHeart();
            if (startCount >= 1440) break;
            if (heartRate != 0) {
                heartArray[startCount] = heartRate;
            }
        }

        float top = 0;
        if (maxDayHr % 10 == 0) {
            top = maxDayHr;
        } else {
            top = (((int) maxDayHr / 10) + 1) * 10;
        }

        ChartDataUtil.initDataChartView(LineChartViewHealthHeart, -0.5f, top + 10, heartArray.length, 30);
        LineChartViewHealthHeart.setLineChartData(ChartDataUtil.getHistoryHeartDayChart(getActivity(), heartArray, mFace, 0, top));
    }

    private void initHealthData(String date) {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTimeInMillis(DateUtil.getDefaultLongMi(date + " 00:00:00"));
        int maxDay = calendar.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
        int minDay = calendar.getActualMinimum(java.util.Calendar.DAY_OF_MONTH);
        calendar.set(java.util.Calendar.DAY_OF_MONTH, maxDay);
        String maxDaySting = DateUtil.getDefaultFormatTime(calendar.getTime());
        calendar.set(java.util.Calendar.DAY_OF_MONTH, minDay);
        String minDaySting = DateUtil.getDefaultFormatTime(calendar.getTime());
        Map<String, Calendar> map = new HashMap<>();
        String[] todayArray = DateUtil.getEcgFormatTodayString(System.currentTimeMillis()).split("\\.");
        Calendar calendarSchemeToday = getSchemeCalendar(Integer.valueOf(todayArray[0]), Integer.valueOf(todayArray[1]), Integer.valueOf(todayArray[2]));
        map.put(calendarSchemeToday.toString(), calendarSchemeToday);//今天默认灰色
        todayHealths = HealthDataDaoManager.queryDayData(date + " 00:00:00", date + " 23:59:59");
        showTempData(date);
        List<HealthData> healthDataList = HealthDataDaoManager.queryDayData(minDaySting + " 00:00:00", maxDaySting + " 23:59:59");

        for (HealthData healthData : healthDataList) {
            String time = "20" + healthData.getTime().split(" ")[0];
            String[] dateArray = time.split("\\.");
            ExerciseRecodeData exerciseRecodeData = new ExerciseRecodeData();
            exerciseRecodeData.setEcg(ExerciseRecodeData.HasData);
            Calendar calendarScheme = getSchemeCalendar(Integer.valueOf(dateArray[0]), Integer.valueOf(dateArray[1]), Integer.valueOf(dateArray[2]));
            map.put(calendarScheme.toString(), calendarScheme);
        }
        CalendarViewSleepMonth.setSchemeDate(map);
        if (todayHealths == null || todayHealths.size() == 0) {
            clearData();
            return;
        }
        showHealthData(0);
        int maxHrv = 0;
        int maxPressure = 0;
        int minHrv = 300;
        int minPressure = 300;
        for (HealthData healthData1 : healthDataList) {
            int hrv = healthData1.getHrv();
            int pressure = healthData1.getPressure();
            maxHrv = Math.max(maxHrv, hrv);
            minHrv = Math.min(minHrv, hrv);
            maxPressure = Math.max(maxPressure, pressure);
            minPressure = Math.min(minPressure, pressure);
        }


    }
    private void setPressureLevel(int pressure, HealthData healthData) {
        String levelHrv = "--";
        int color = Color.WHITE;
        int id = R.id.RadioButton_stress1;
        int stressLevel = HealthDataUtils.getStressLevel(pressure);
        String stressAdviceString = stressAdvice[stressLevel];
        levelHrv = stressContent[stressLevel];
        color = hrvColor[stressLevel];
        id = getResources().getIdentifier("RadioButton_stress" + (stressLevel + 1),
                "id", getActivity().getPackageName());
        if (healthData != null) {
            int lastValue = healthData.getPressure();
            setDrawableRight(pressure < lastValue ? R.drawable.data_down : R.drawable.data_up, tvStressValue);
        }
        RadioGroupStress.check(id);
        tvStressAdvice.setText(stressAdviceString);
        String stressValue = String.valueOf(pressure == 0 ? "--" : pressure + " " + levelHrv);
        tvStressValue.setText(stressValue);
        tvStressValue.setTextColor(color);
    }

    private void showTempData(String date) {
        List<TemperatureHistoryData> temperatureHistoryDataList = TempHistoryDataDaoManager.queryDayData(date);
        float count = 0;
        float totalDayHr = 0;
        float maxDayHr = 0;
        float minDayHr = 300;
        for (int i = 0; i < temperatureHistoryDataList.size(); i++) {
            TemperatureHistoryData temperatureHistoryData = temperatureHistoryDataList.get(i);
            float data = temperatureHistoryData.getTempValue();
            if (data != 0) {
                count++;
                totalDayHr += data;
                maxDayHr = Math.max(maxDayHr, data);
                minDayHr = Math.min(minDayHr, data);
            }
        }
        NumberFormat numberFormat = ResolveData.getNumberFormat(1);
        numberFormat.setRoundingMode(RoundingMode.DOWN);
        float avgHR = count == 0 ? 0 : totalDayHr / count;
        tvTempValue.setText(avgHR == 0 ? "--" : numberFormat.format(avgHR) + "℃");
        tvTempMaxValue.setText(maxDayHr == 0 ? "--" : maxDayHr + "℃");
        tvTempMinValue.setText(minDayHr == 300 ? "--" : minDayHr + "℃");
    }

    private void showHealthData(int position) {
        HealthData healthData = todayHealths.get(position);
        HealthData lastHealthData = position < todayHealths.size() - 1 ? todayHealths.get(position + 1) : todayHealths.get(position);
        int hrv = healthData.getHrv();
        int pressure = healthData.getPressure();
        tvHrvValue.setText(String.valueOf(hrv));
        setHrvLevel(hrv, lastHealthData);
        setPressureLevel(pressure, lastHealthData);
    }

    private Calendar getSchemeCalendar(int year, int month, int day) {
        Calendar calendar = new Calendar();
        calendar.setYear(year);
        calendar.setMonth(month);
        calendar.setDay(day);
        calendar.setSchemeColor(Color.RED);//如果单独标记颜色、则会使用这个颜色
        calendar.setScheme("");
        return calendar;
    }

    private void clearData() {

        tvHrvValue.setText("--");

        tvHrvAdvice.setText("");
        tvStressValue.setText("--");
        tvStressAdvice.setText("");
        setDrawableRight(0, tvHrvValue);
        setDrawableRight(0, tvStressValue);
        ivHrvLevel0.setVisibility(View.INVISIBLE);
        ivHrvLevel1.setVisibility(View.INVISIBLE);
        ivHrvLevel2.setVisibility(View.INVISIBLE);
        ivHrvLevel3.setVisibility(View.INVISIBLE);
    }

    private void setHrvLevel(int hrv, HealthData lastHealthData) {
        int hrvLevel = HealthDataUtils.getHrvLevel(hrv);
        String levelHrv = "--";
        int color = Color.WHITE;
        levelHrv = hrvContent[hrvLevel];
        color = hrvColor[hrvLevel];
        String adviceHRV = hrvAdvice[hrvLevel];
        tvHrvAdvice.setText(adviceHRV);
        ivHrvLevel0.setVisibility(hrvLevel == 3 ? View.VISIBLE : View.INVISIBLE);
        ivHrvLevel1.setVisibility(hrvLevel == 2 ? View.VISIBLE : View.INVISIBLE);
        ivHrvLevel2.setVisibility(hrvLevel == 1 ? View.VISIBLE : View.INVISIBLE);
        ivHrvLevel3.setVisibility(hrvLevel == 0 ? View.VISIBLE : View.INVISIBLE);
        String hrvValue = String.valueOf(hrv == 0 ? "--" : hrv + " " + levelHrv);
        if (lastHealthData != null) {
            int lastValue = lastHealthData.getHrv();
            setDrawableRight(hrv < lastValue ? R.drawable.data_down : R.drawable.data_up, tvHrvValue);
        }
        tvHrvValue.setText(hrvValue);
        tvHrvValue.setTextColor(color);
    }

    private void setDrawableRight(int id, TextView textView) {
        if (id == 0) {
            textView.setCompoundDrawables(null, null, null, null);
            return;
        }
        Drawable drawable = getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawables(null, null, drawable, null);
    }


    private void startMeasureHeart(boolean startMeasure) {
        if (BleManager.getInstance().isConnected()) {
            ExerciseMode exerciseMode = new ExerciseMode();
            exerciseMode.setEnableStatus(startMeasure ? ExerciseMode.Status_START : ExerciseMode.Mode_RUN);
            sendData(Set_EXERCISE_MODE, exerciseMode);
        }


    }

    @OnClick({R.id.iv_stress_data,R.id.tv_body_pressure,R.id.iv_temp_data, R.id.ExpandIconView, R.id.bt_health_title, R.id.tv_health_hr, R.id.tv_hrv, R.id.tv_health_heart, R.id.iv_hrv_data})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_health_title:
            case R.id.ExpandIconView:
                if (CalendarLayout.isExpand()) {
                    CalendarLayout.shrink();
                } else {
                    CalendarLayout.expand();
                    ScrollView.fling(0);
                    ScrollView.smoothScrollTo(0, 0);
                }
                break;
            case R.id.tv_health_hr:
                startTipsActivity(HeartTipsActivity.TipsType_Heart);
                break;

            case R.id.tv_hrv:
                startTipsActivity(HeartTipsActivity.TipsType_HRV);
                break;
            case R.id.tv_health_heart:
                startActivity(HeartHistoryActivity.class);
                break;

            case R.id.iv_hrv_data:
                startHealthActivity(HealthHistoryActivity.DATA_HRV);
                break;
            case R.id.iv_temp_data:
                startActivity(TempHistoryActivity.class);
                break;
            case R.id.iv_stress_data:
                startHealthActivity(HealthHistoryActivity.DATA_PRESSURE);
                break;
            case R.id.tv_body_pressure:
                startTipsActivity(HeartTipsActivity.TipsType_Stress);
                break;
        }
    }

    private void startHealthActivity(int type) {
        Intent intent = new Intent(getActivity(), HealthHistoryActivity.class);
        intent.putExtra(HistoryActivity.KEY_DATA_TYPE, type);
        startActivity(intent);
    }

    private void startTipsActivity(int type) {
        Intent intent = new Intent(getActivity(), HeartTipsActivity.class);
        intent.putExtra(HeartTipsActivity.TipsType, type);
        startActivity(intent);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        unSubscribe(subscription);
    }

    @Override
    public void dataCallback(Map<String, String> maps, SendCmdState sendCmdState) {
        switch (sendCmdState) {
            case SET_STEP_MODEL:
                String temp = maps.get(DeviceKey.KTemp);
                if (TemperatureView.getVisibility() == View.VISIBLE)
                    TemperatureView.setTempCValue(Float.valueOf(temp));
                break;

        }
    }

    @Override
    public void dataCallback(DeviceBean deviceBean, SendCmdState sendCmdState) {

    }


}
